package edu.ccut.saturn.workflow.startWorkFlowModule.code;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import edu.ccut.saturn.component.IParameterContext;
import edu.ccut.saturn.component.SaturnData;
import edu.ccut.saturn.workflow.common.WorkFlowTools;
import edu.ccut.saturn.workflow.model.ActivityInfo;

public class GetParticipantFromLogic implements IParticipantGeter {


	@SuppressWarnings("unchecked")
	public List<SaturnData> getParticipant(SaturnData workItemInstance,
			ActivityInfo currentActivityInfo, IParameterContext parameterContext) 
			throws Exception {
		String userName = null;
		String userSerialNo = null;
		List<SaturnData> wiParticipantDatas = new ArrayList<SaturnData>();
		Map<String, String> workFlowParamMap = (Map<String, String>) parameterContext
		.getParameterValue(2);
		Map<String, String> customParamMap = (Map<String, String>) parameterContext
		.getParameterValue(4);
		//合并为一个容器
		workFlowParamMap.putAll(customParamMap);
		List<HashMap<String, String>> userInfos =WorkFlowTools.executeCustomUserLogic(
				currentActivityInfo, workFlowParamMap);
		for (HashMap userInfo : userInfos) {
			userName = (String) userInfo.get("userName");
			userSerialNo = (String) userInfo.get("userSerialNo");
			SaturnData wiParticipantData = WorkFlowTools.
		    getParticipantInstanceWithValues(userSerialNo,userName);
			wiParticipantDatas.add(wiParticipantData);
		}
		return wiParticipantDatas;
	} 

	

}
